<div id="developerGrid"></div>
<script>
	$(function() {
		var columns = [
			{
				title : '开发者ID',
				name : 'developerId',
				width : 150
			},
			{
				title : '用户名称',
				name : 'name',
				width : 150
			},
			{
				title : '用户密码',
				name : 'password',
				width : 150
			},
			{
				title : '邮箱',
				name : 'email',
				width : 'auto'
			}
		];
		var buttons = [
			{
				content : '<button class="btn btn-primary" type="button"><span class="glyphicon glyphicon-plus"><span>添加</button>',
				action : 'add'
			}, 
			{
				content : '<button class="btn btn-success" type="button"><span class="glyphicon glyphicon-edit"><span>修改</button>',
				action : 'modify'
			}, 
			{
				content : '<button class="btn btn-danger" type="button"><span class="glyphicon glyphicon-remove"><span>删除</button>',
				action : 'delete'
			}
		];
		$('#developerGrid').grid({
			identity : 'id',
			columns : columns,
			querys: [{title: '开发者ID', value: 'developerId'},{title: '姓名', value: 'name'},{title: '邮箱', value: 'email'}],
			buttons : buttons,
			url : 'developer/pagingquery'
		}).on({
			'add': function(){
				developerManager.add($(this));
			},
			'modify': function(e, data){
				var indexs = data.data;
                var $this = $(this);
                if(indexs.length == 0){
                     $this.message({
                         type: 'warning',
                          content: '请选择一条记录进行修改'
                 	 });
                     return;
                 }
                 if(indexs.length > 1){
                     $this.message({
                         type: 'warning',
                           content: '只能选择一条记录进行修改'
                     });
                     return;
                 }
                developerManager.update($this, data.item[0]);
			},
			'delete': function(e, data){
				 var indexs = data.data;
                 var $this = $(this)
                 if(indexs.length == 0){
                      $this.message({
                           type: 'warning',
                           content: '请选择要操作的记录'
                   	  });
                       return;
                 }
                 $this.confirm({
                         content: '确定要删除所选记录吗?',
                         callBack: function(){ developerManager.del($this, data.item);}
                 });
			}
		});
	}); 
</script>
